// pages/ptgoods/ptgoods.js

const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');
const WxParse = require('../../wxParse/wxParse.js');

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid:'',
    channel1: [{
      iconUrl: '/static/images/toux1.jpg',
    }],
    id: '',
    detailss: [
    ],
    goods: {
  
    }
  },

  getzhinan() {
    let that = this
    util.request(api.QueryListGuide, {
    }, {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'X-Qxmall-Token': wx.getStorageSync('token')
      }).then(function (res) {
        console.log(res.data)
        if (res.code == 200) {
          that.setData({
            detailss: res.data.listGuide
          })
        }
      })
  },

  queryUserComm() {
    let that = this
    util.request(api.QueryGroupIdInfo + "?id=" + that.data.id, {
    }, 'get', {
      }).then(function (res) {
        console.log(res)
        let ceshi = res.data.groupInfo.neceInfo.content
        WxParse.wxParse('article', 'html', ceshi, that, 5);
        var need = res.data.groupInfo.discountPernum;
        var gsh=res.data.groupInfo.neceInfo.joinUserImg.length
        need=need-gsh
        console.log("ren"+need)
        that.setData({
          end: res.data.groupInfo.endTime,
          goods: res.data.groupInfo,
        })
      });
  },

  queryCreateUseImg() {
    let that = this
    util.request(api.QueryCreateUseImg + "/" + that.data.openid, {
    }, 'get', {
      }).then(function (res) {
        console.log(res)
        let bb = res.data.userImg
        bb.split(",")
        console.log(bb)
      });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      id: options.id,
      openid: options.userid
    })

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.queryUserComm()
    this.getzhinan()
    this.queryCreateUseImg()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: '我正在参加拼团：' + this.data.goods.commName,
      desc: '欢迎购物！',
      path: '/pages/ptshop/ptshop?id=' + this.data.goods.id,
      success: function () {
        this.setData({
          openShare: false,
        });
      }
    }
    return shareObj
  }
})